package bean;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


import java.sql.*;

public class BDConexion {

    private Connection conexion;
    static String bd = "Proyecto";
    static String user = "root";
    static String password = "root";
    static String ip = "192.168.0.185";//"10.0.0.10";
    static String server = "jdbc:mysql://"+ip+"/" + bd;

    /**
     * Creates a new instance of BasedeDatos
     */
    public BDConexion() {
    }

    public boolean establecerConexion() {
        try {
            Class.forName("com.mysql.jdbc.Driver");
            conexion = DriverManager.getConnection(server, user, password);
            return true;
        } catch (Exception e) {
            System.out.println("Imposible realizar conexion con la BD");
            e.printStackTrace();
            return false;
        }
    }

    public Connection getConexion() {
        return conexion;
    }

    public boolean cerrar(ResultSet rs) {
        if (rs != null) {
            try {
                rs.close();
                return true;
            } catch (Exception e) {
                System.out.print("No es posible cerrar la Conexion");
                return false;
            }
        }
        return false;
    }

    public boolean cerrar(java.sql.Statement stmt) {
        if (stmt != null) {
            try {
                stmt.close();
                return true;
            } catch (Exception e) {
                return false;
            }
        }
        return false;
    }

    public boolean destruir() {
        if (conexion != null) {
            try {
                conexion.close();
                return true;
            } catch (Exception e) {
                return false;
            }
        }
        return false;
    }
}